<script lang="ts" setup>
import { message } from 'ant-design-vue';

import { useVbenForm } from '#/adapter/form';

const [QueryForm, formApi] = useVbenForm({
  // 默认展开
  collapsed: false,
  // 所有表单项共用，可单独在表单内覆盖
  commonConfig: {
    // 所有表单项
    componentProps: {
      class: 'w-full',
    },
  },
  // 提交函数
  handleReset: resetSubmit,
  handleSubmit: onSubmit,
  // 垂直布局，label和input在不同行，值为vertical
  // 水平布局，label和input在同一行
  layout: 'horizontal',
  schema: [
    {
      // 组件需要在 #/adapter.ts内注册，并加上类型
      component: 'Input',
      // 对应组件的参数
      componentProps: {
        placeholder: '请输入关键字',
      },
      // 字段名
      fieldName: 'Keyword',
      // 界面显示的label
      label: '用户账号',
    },

    {
      component: 'Select',
      componentProps: {
        allowClear: true,
        filterOption: true,
        options: [
          {
            label: '正常',
            value: '1',
          },
          {
            label: '禁用',
            value: '2',
          },
        ],
        placeholder: '请选择',
        showSearch: true,
      },
      fieldName: 'Status',
      label: '状态',
    },

  ],
  // 是否可展开
  showCollapseButton: true,
  submitButtonOptions: {
    content: '查询',
  },
  wrapperClass: 'grid-cols-1 md:grid-cols-3',
});

const emits = defineEmits(['query', 'reset'])

function onSubmit(values: Record<string, any>) {
  console.log('查询', values);
  emits('query', values)
}

async function resetSubmit(values: Record<string, any>) {


  await formApi.resetForm()
  let temp = await formApi.getValues()
  console.log('重置', temp);

  emits('reset', temp)
}
</script>

<template>
  <QueryForm />
</template>
